package chuangyi.com.org.ViewModel;

import android.content.Context;
import android.databinding.Bindable;
import android.view.View;

import chuangyi.com.org.DOMIHome.Fragments.HomeFragment;
import chuangyi.com.org.DOMIHome.HomeActivity;
import chuangyi.com.org.DOMIHome.Utils.WebApi;

/**
 * Created by zxh on 16/12/14.
 */

public class MyFeedbackModel extends ObservableWithGoBackHandler {
    private String contact;
    private String feel;

    @Bindable
    public String getContact() {
        return contact;
    }

    public void setContact(String contact) {
        this.contact = contact;
    }

    @Bindable
    public String getFeel() {
        return feel;
    }

    public void setFeel(String feel) {
        this.feel = feel;
    }

    public MyFeedbackModel(Context context) {
        super(context);
        getHandler().setTitle("意见反馈");
    }

    public void onClickCommit(View view) {
        if (contact == null || contact.equals("")) {
            showToast("请填写您的联系方式");
        } else if (feel == null || feel.equals("")) {
            showToast("请填写您的使用感受");
        } else {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    if (WebApi.sendSuggest(getContext(), contact, feel)) {
                        showToast("我们已收到您的反馈");
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                HomeActivity.popFragment();
                            }
                        });
                    }
                }
            }).start();
        }
    }
}
